<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp" %>
<html>
    <head>
        <title>设备维护信息管理</title>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <meta name="decorator" content="ani"/>
        <%@ include file="/webpage/include/bootstraptable.jsp" %>
        <%@include file="/webpage/include/treeview.jsp" %>
        <%@include file="yjMaintenanceList.js" %>
    </head>
    <body>
        <div class="wrapper wrapper-content">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h3 class="panel-title">设备维护信息列表</h3>
                </div>
                <div class="panel-body">
                    <sys:message content="${message}"/>

                    <!-- 搜索 -->
                    <div class="accordion-group">
                        <div id="collapseTwo" class="accordion-body collapse">
                            <div class="accordion-inner">
                                <input type="hidden" id="pageIndex" value="${pageIndex}">
                                <form:form id="searchForm" modelAttribute="yjMaintenance"
                                           class="form form-horizontal well clearfix">
                                    <div class="col-xs-12 col-sm-6 col-md-4">
                                        <label class="label-item single-overflow pull-left" title="设备维护号：">设备维护号：</label>
                                        <sys:gridselect url="${ctx}/web/yjMaintenance/data" id="equipment" name="equipment.id" value="${yjMaintenance.equipment.id}" labelName="equipment.name" labelValue="${wxAgentsEquipment.equipment.name}"
                                                        title="选择设备" cssClass="form-control required" fieldLabels="id|设备名" fieldKeys="id|name" searchLabels="id|设备名" searchKeys="id|name" ></sys:gridselect>
                                    </div>

                                    <c:if test="${list!=null}">
                                        <div class="col-xs-12 col-sm-6 col-md-4">
                                            <label class="label-item single-overflow pull-left" title="总代理商：">总代理商：</label>
                                            <select class="layui-select form-control" name="total" id="total"  >
                                                <option value="">未选择</option>

                                                <c:forEach items="${list}"  var ="item">
                                                    <option value="${item.id}">${item.userName}
                                                        <c:if test="${!empty item.remarks}">
                                                            —${item.remarks}
                                                        </c:if>
                                                    </option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </c:if>

                                    <c:if test="${list!=null or (list==null and childList!=null and childList.size()>0 )}">
                                        <div class="col-xs-12 col-sm-6 col-md-4">
                                            <label class="label-item single-overflow pull-left" title="子代理商：">子代理商：</label>
                                            <select class="layui-select form-control" name="top" id="top"    >
                                                <option value="未选择">未选择</option>
                                                <c:forEach items="${childList}"  var ="item">
                                                    <option value="${item.id}">${item.userName}
                                                        <c:if test="${!empty item.remarks}">
                                                            —${item.remarks}
                                                        </c:if>
                                                    </option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </c:if>

                                    <c:if test="${list!=null or (list==null and shopList!=null and shopList.size()>0)}" >
                                        <div class="col-xs-12 col-sm-6 col-md-4">
                                            <label class="label-item single-overflow pull-left" title="门店：">门店：</label>
                                            <select class="layui-select form-control" name="shop" id="shop">

                                                <option value="未选择">未选择</option>
                                                <c:forEach items="${shopList}"  var ="item">
                                                    <option value="${item.id}">${item.userName}
                                                        <c:if test="${!empty item.remarks}">
                                                            —${item.remarks}
                                                        </c:if>
                                                    </option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </c:if>

                                    <div class="col-xs-12 col-sm-6 col-md-4">
                                        <div style="margin-top:26px">
                                            <a id="search" class="btn btn-primary btn-rounded  btn-bordered btn-sm"><i
                                                    class="fa fa-search"></i> 查询</a>
                                            <a id="reset" class="btn btn-primary btn-rounded  btn-bordered btn-sm"><i
                                                    class="fa fa-refresh"></i> 重置</a>
                                        </div>
                                    </div>
                                </form:form>
                            </div>
                        </div>
                    </div>

                    <!-- 工具栏 -->
                    <div id="toolbar">

                        <a class="accordion-toggle btn btn-default" data-toggle="collapse" data-parent="#accordion2"
                           href="#collapseTwo">
                            <i class="fa fa-search"></i> 检索
                        </a>
                    </div>

                    <!-- 表格 -->
                    <table id="yjMaintenanceTable" data-toolbar="#toolbar"></table>
                </div>
            </div>
        </div>
        <script  >
            $(document).ready(function(){
                $('#total').change(function(){
                    var parentId=$(this).children('option:selected').val();
                    if(!parentId){
                        return;
                    }
                    jp.get("${ctx}/web/wxAgentsRecording/selectChilds?parentId="+parentId, function(data){
                        var item;
                        if(data.body.childList&&data.body.childList.length>0) {
                            var st = "<option value=\"\">未选择</option>";
                            for (var s = 0; s < data.body.childList.length; s++) {
                                item=data.body.childList[s];
                                var remarks=item.remarks?"—"+item.remarks:"";
                                st = st + "<option value='" + item.id + "'>" + item.userName+remarks + "</option>"
                            }
                            if (st != "") {
                                $("#top").empty();
                            }
                            $("#top").append(st);
                        }
                        if(data.body.shopList&&data.body.shopList.length>0){
                            var  st1="<option value=\"\">未选择</option>";
                            for(var ss=0;ss<data.body.shopList.length;ss++){
                                item=data.body.childList[s];
                                var remarks=item.remarks?"—"+item.remarks:"";
                                st1=st1+"<option value='"+item.id+"'>"+ item.userName+remarks +"</option>"
                            }
                            if(st1!=""){
                                $("#shop").empty();
                            }
                            $("#shop").append(st1);
                        }
                    });
                });
                $('#top').change(function(){
                    var parentId=$(this).children('option:selected').val();
                    if(!parentId){
                        return;
                    }
                    jp.get("${ctx}/web/wxAgentsRecording/selectChilds?parentId="+parentId, function(data){
                        var item;
                        if(data.body.shopList!=null &&data.body.shopList!=[]){
                            var  st1="<option value=\"未选择\">未选择</option>";
                            for(var ss=0;ss<data.body.shopList.length;ss++){
                                item=data.body.shopList[ss];
                                var remarks=item.remarks?"—"+item.remarks:"";
                                st1=st1+"<option value='"+item.id+"'>"+ item.userName+item.remarks +"</option>"
                            }
                            if(st1!=""){
                                $("#shop").empty();
                            }
                            $("#shop").append(st1);
                        }
                    });
                });
            })
        </script>
    </body>
</html>
